package cn.bdqn.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import cn.bdqn.entity.DevUser;
import cn.bdqn.service.DevUserService;


@Controller
@RequestMapping("/devUser")
public class DevUserController {

	@Autowired
	private DevUserService devUserService;
	
	@RequestMapping("/disLogin")
	public String disLogin() throws Exception{
		return "devLogin";
	}
	
	
	@RequestMapping("/login")
	public String login(HttpServletRequest request,HttpSession session,
						@RequestParam(value="devCode",required=false)String username,
						@RequestParam(value="devPassword",required=false)String password)
								throws Exception{
		DevUser loginDevUser = devUserService.login(username,password);
		
		if(loginDevUser != null){
			//登陆成功
			session.setAttribute("devUser", loginDevUser);
			return "redirect:/devApp/disMain";
		}else{
			//登陆失败
			request.setAttribute("loginInfo", "用户名或密码错误...");
			return "devLogin";
		}
		
	}
	
	/**
	 * 退出
	 * @param session
	 * @return
	 */
	@RequestMapping("/logout")
	public String logout(HttpSession session) throws Exception{
		//清除session
		session.removeAttribute("UserSession");
		return "devLogin";
	}
	
}
